﻿Shader "Custom/Superposition"
{
    Properties
    {
        _MainTex ("MainTex", 2D) = "white" {}
		_SecondaryTex ("SecondaryTex", 2D) = "white" {}
		_Speed("Speed",Range(0,5)) = 1
    }
    SubShader
    {
        // No culling or depth
        Cull Back ZWrite Off ZTest Always
		Blend SrcAlpha OneMinusSrcAlpha

		//透明渲染队列
		Tags { "Queue"="Transparent" }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

			sampler2D _MainTex;
			sampler2D _SecondaryTex;
			float _Speed;

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 mainCol = tex2D(_MainTex, i.uv);
				fixed4 secondaryCol = tex2D(_SecondaryTex, i.uv);

				//重定向至0-1
				half weight = (cos(_Time.y * _Speed) + 1) * 0.5;
				fixed4 col = lerp(mainCol,secondaryCol,weight);
                return col;
            }
            ENDCG
        }
    }
}
